package com.ebiz.jo.imageBrowser
{
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	
	public class ImageLoader extends Loader{
		public var oriW:Number = 0;
		public var oriH:Number = 0;
		public var stretch:Boolean = false;
		public var loadingMovie:Sprite;
		public function ImageLoader(){
			super();
		}
		public function loadURL($url:String):void{
			this.load(new URLRequest($url));
		}
		override public function load(request:URLRequest, context:LoaderContext=null) : void{
			//		try{
			this.contentLoaderInfo.addEventListener(Event.COMPLETE,evtComplete);
			super.load(request,context);
			//		}catch(_e:Error){
			
			//		}
		}
		public function evtComplete(_e:Event):void{
			this.contentLoaderInfo.removeEventListener(Event.COMPLETE,evtComplete);
			this.width = this.oriW;
			if(stretch){
				this.height = this.oriH;
			}else{
				this.scaleY = this.scaleX;
			}
			if(loadingMovie && loadingMovie.parent){
				(loadingMovie.parent as DisplayObjectContainer).removeChild(this.loadingMovie);
			}
			(this.parent as DisplayObjectContainer).alpha = 1;
		}
	}
}